package cn.com.cennavi.config;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
import java.util.UUID;

/**
 * 读取kafka的默认配置文件
 * 
 * @Description
 * @author buf
 * @date 2017年3月8日 下午2:37:23
 */
public class KafkaConfigFile {

	public  String metadata_broker_list;
	public  Properties props = null;
	public  HashMap<String, String> kafkaParams = null;
	public  String topics = null;
	public  HashSet<String> topicsSet = null;

	public  KafkaConfigFile() {

	}

	public void init() throws FileNotFoundException, IOException {
		props = new Properties();
		props.load(new FileInputStream("./configfiles/kafkaConfig.properties"));
		topics = props.getProperty("kafka.topics");
		topicsSet = new HashSet<String>(Arrays.asList(topics.split(",")));
		metadata_broker_list = props.getProperty("metadata.broker.list");
		kafkaParams = new HashMap<String, String>();
		kafkaParams.put("zookeeper.connect", props.getProperty("zookeeper.connect"));
		kafkaParams.put("group.id", UUID.randomUUID().toString());
		kafkaParams.put("auto.offset.reset", props.getProperty("auto.offset.reset"));
		kafkaParams.put("metadata.broker.list", props.getProperty("metadata.broker.list"));
		kafkaParams.put("bootstrap.servers", props.getProperty("bootstrap.servers"));
		kafkaParams.put("fetch.message.max.bytes", "10485760");

	}

	public String getMetadata_broker_list() throws FileNotFoundException, IOException {
	
		return metadata_broker_list;
	}

	public HashMap<String, String> getKafkaParams() throws FileNotFoundException, IOException {
	
		return this.kafkaParams;
	}

	public HashSet<String> getTopicsSet() throws FileNotFoundException, IOException {

		return this.topicsSet;
	}

	public void setTopicsSet(HashSet<String> topicsSet1) {
		this.topicsSet = topicsSet1;

	}

	public static void main(String[] args) throws FileNotFoundException, IOException {
		System.out.println(new KafkaConfigFile().getMetadata_broker_list());
	}
}
